{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "![JohnSnowLabs](https://nlp.johnsnowlabs.com/assets/images/logo.png)\n",
    "\n",
    "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JohnSnowLabs/nlu/blob/master/examples/colab/ocr/table_extraction.ipynb)\n",
    "\n",
    "# Table extraction for PDFs, PPTs and Docx files\n",
    "In this notebook we will extract tables in text format from 3 different PDF files using OCR for `PDFs`, `PPTs` and `DOCX` files.\n",
    "\n",
    "\n",
    "| NLU Spell            | Transformer Class                                                                       |\n",
    "|----------------------|-----------------------------------------------------------------------------------------|\n",
    "| nlu.load(`pdf2table`) | [PdfToTextTable](https://nlp.johnsnowlabs.com/docs/en/ocr_pipeline_components#pdftotexttable) |              \n",
    "| nlu.load(`ppt2table`) | [PptToTextTable](https://nlp.johnsnowlabs.com/docs/en/ocr_pipeline_components#ppttotexttable)     |              \n",
    "| nlu.load(`doc2table`) | [DocToTextTable](https://nlp.johnsnowlabs.com/docs/en/ocr_pipeline_components#doctotexttable)     |              \n",
    "\n",
    "\n",
    "When your nlu pipeline contains a `ocr spell` the predict method will accept the following inputs : \n",
    "\n",
    "- a `string` pointing to a folder or to a file\n",
    "- a `list`, `numpy array` or `Pandas Series` containing paths pointing to folders or files \n",
    "- a `Pandas Dataframe` or `Spark Dataframe` containing a column named `path` which has one path entry per row pointing to folders or files\n",
    "\n",
    "For every path in the input passed to the `predict()` method, nlu will distinguish between two cases: \n",
    "1. If the path points to a `file`, nlu will apply OCR transformers to it, if the file type is applicable with the currently loaded OCR pipeline.\n",
    "2. If the path points to a `folder`, nlu will recuirsively search for files in the folder and subfolders which have file types wich are applicable with the loaded OCR pipeline.\n",
    "\n",
    "NLU checks the file endings to determine wether the OCR models can be applied or not, i.e. `.pdf`, `.doc`, `.ppt` etc.. \n",
    "If your files lack these endings, NLU will not process them.\n"
   ],
   "metadata": {
    "id": "BK-Oh7-Oo4_6",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "yvrnnikdPOGs",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from johnsnowlabs import nlp\n",
    "nlp.install(visual=True)\n",
    "nlp.start(visual=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Authorize your environment for OCR\n",
    "You need a Spark OCR license for using OCR spells, which is available for [free here](https://www.johnsnowlabs.com/spark-nlp-try-free/) \n",
    "\n",
    "Either upload the json credentials file to the `/content` folder of google colab or manually pass the credentials to `nlu.auth`.      \n",
    "For more details on how to authorize your environment, check out the [OCR documentaton page](https://nlu.johnsnowlabs.com/docs/en/nlu_for_ocr#authorize-via-providing-string-parameters)"
   ],
   "metadata": {
    "id": "nBqFTd4RNydT",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Download some `PDF` files we can apply OCR on\n"
   ],
   "metadata": {
    "id": "V-5co2ZyGo12",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "! wget https://github.com/JohnSnowLabs/nlu/raw/4.0.0/tests/datasets/ocr/pdf/tables.pdf\n",
    "! wget https://github.com/JohnSnowLabs/nlu/raw/4.0.0/tests/datasets/ocr/pdf/insurance.pdf"
   ],
   "metadata": {
    "id": "Qrjl7lojG7_D",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Create helper function to print talbes easily"
   ],
   "metadata": {
    "id": "lDTvZ8TXWhkt",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "def print_tables(results):\n",
    "  for i, df in enumerate(results):\n",
    "    print(f\"Table {i+1}:\")\n",
    "    print(df)\n",
    "    print(\"\\n\")"
   ],
   "metadata": {
    "id": "Oq06RGGCWAwK",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 3,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Use the load the `pdf2table` spell\n",
    "At first step we will run the spell on simple `pdf` file then we will run this on more complex `pdf` that contains multiple tables"
   ],
   "metadata": {
    "id": "0lD0AgmpH8Re",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "results = nlp.load('pdf2table').predict('/content/tables.pdf')\n",
    "print_tables(results)"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "nX1C5LIh_Pqh",
    "outputId": "d9a237f4-aaee-44cc-831e-af3fee845de9",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 18,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Table 1:\n",
      "     mpg cyl   disp   hp  drat     wt   qsec vs am gear\n",
      "1   21.0   6  160.0  110  3.90  2.620  16.46  0  1    4\n",
      "2   21.0   6  160.0  110  3.90  2.875  17.02  0  1    4\n",
      "3   22.8   4  108.0   93  3.85  2.320  18.61  1  1    4\n",
      "4   21.4   6  258.0  110  3.08  3.215  19.44  1  0    3\n",
      "5   18.7   8  360.0  175  3.15  3.440  17.02  0  0    3\n",
      "6   18.1   6  225.0  105  2.76  3.460  20.22  1  0    3\n",
      "7   14.3   8  360.0  245  3.21  3.570  15.84  0  0    3\n",
      "8   24.4   4  146.7   62  3.69  3.190  20.00  1  0    4\n",
      "9   22.8   4  140.8   95  3.92  3.150  22.90  1  0    4\n",
      "10  19.2   6  167.6  123  3.92  3.440  18.30  1  0    4\n",
      "11  17.8   6  167.6  123  3.92  3.440  18.90  1  0    4\n",
      "12  16.4   8  275.8  180  3.07  4.070  17.40  0  0    3\n",
      "13  17.3   8  275.8  180  3.07  3.730  17.60  0  0    3\n",
      "14  15.2   8  275.8  180  3.07  3.780  18.00  0  0    3\n",
      "15  10.4   8  472.0  205  2.93  5.250  17.98  0  0    3\n",
      "16  10.4   8  460.0  215  3.00  5.424  17.82  0  0    3\n",
      "17  14.7   8  440.0  230  3.23  5.345  17.42  0  0    3\n",
      "18  32.4   4   78.7   66  4.08  2.200  19.47  1  1    4\n",
      "19  30.4   4   75.7   52  4.93  1.615  18.52  1  1    4\n",
      "20  33.9   4   71.1   65  4.22  1.835  19.90  1  1    4\n",
      "21  21.5   4  120.1   97  3.70  2.465  20.01  1  0    3\n",
      "22  15.5   8  318.0  150  2.76  3.520  16.87  0  0    3\n",
      "23  15.2   8  304.0  150  3.15  3.435  17.30  0  0    3\n",
      "24  13.3   8  350.0  245  3.73  3.840  15.41  0  0    3\n",
      "25  19.2   8  400.0  175  3.08  3.845  17.05  0  0    3\n",
      "26  27.3   4   79.0   66  4.08  1.935  18.90  1  1    4\n",
      "27  26.0   4  120.3   91  4.43  2.140  16.70  0  1    5\n",
      "28  30.4   4   95.1  113  3.77  1.513  16.90  1  1    5\n",
      "29  15.8   8  351.0  264  4.22  3.170  14.50  0  1    5\n",
      "30  19.7   6  145.0  175  3.62  2.770  15.50  0  1    5\n",
      "31  15.0   8  301.0  335  3.54  3.570  14.60  0  1    5\n",
      "\n",
      "\n",
      "Table 2:\n",
      "   Sepal.Length Sepal.Width Petal.Length   Petal.Width      Species           \n",
      "1                       5.1          3.5           1.4   0.2 setosa           \n",
      "2                       4.9          3.0           1.4   0.2 setosa           \n",
      "3                       4.7          3.2           1.3   0.2 setosa           \n",
      "4                       4.6          3.1           1.5   0.2 setosa           \n",
      "5                       5.0          3.6           1.4   0.2 setosa           \n",
      "6                       5.4          3.9           1.7   0.4 setosa           \n",
      "7              Sepal.Length  Sepal.Width  Petal.Length  Petal.Width    Species\n",
      "8                   145 6.7          3.3           5.7          2.5  virginica\n",
      "9                   146 6.7          3.0           5.2          2.3  virginica\n",
      "10                  147 6.3          2.5           5.0          1.9  virginica\n",
      "11                  148 6.5          3.0           5.2          2.0  virginica\n",
      "12                  149 6.2          3.4           5.4          2.3  virginica\n",
      "13                  150 5.9          3.0           5.1          1.8  virginica\n",
      "14                                     2                                      \n",
      "\n",
      "\n",
      "Table 3:\n",
      "   supp\n",
      "1    VC\n",
      "2    VC\n",
      "3    VC\n",
      "4    VC\n",
      "5    VC\n",
      "6    VC\n",
      "7    VC\n",
      "8    VC\n",
      "9    VC\n",
      "10   VC\n",
      "11   VC\n",
      "12   VC\n",
      "13   VC\n",
      "14   VC\n",
      "\n",
      "\n"
     ]
    }
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "# You get an array of pandas Dataframes returned, You can easily view them"
   ],
   "metadata": {
    "id": "njnk_bDvB-3w",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 19,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "results[0]"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "D44pEFjsB8pY",
    "outputId": "bc9d6a02-caf9-4fa6-f680-2c63327c8847",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 20,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "     mpg cyl   disp   hp  drat     wt   qsec vs am gear\n",
       "1   21.0   6  160.0  110  3.90  2.620  16.46  0  1    4\n",
       "2   21.0   6  160.0  110  3.90  2.875  17.02  0  1    4\n",
       "3   22.8   4  108.0   93  3.85  2.320  18.61  1  1    4\n",
       "4   21.4   6  258.0  110  3.08  3.215  19.44  1  0    3\n",
       "5   18.7   8  360.0  175  3.15  3.440  17.02  0  0    3\n",
       "6   18.1   6  225.0  105  2.76  3.460  20.22  1  0    3\n",
       "7   14.3   8  360.0  245  3.21  3.570  15.84  0  0    3\n",
       "8   24.4   4  146.7   62  3.69  3.190  20.00  1  0    4\n",
       "9   22.8   4  140.8   95  3.92  3.150  22.90  1  0    4\n",
       "10  19.2   6  167.6  123  3.92  3.440  18.30  1  0    4\n",
       "11  17.8   6  167.6  123  3.92  3.440  18.90  1  0    4\n",
       "12  16.4   8  275.8  180  3.07  4.070  17.40  0  0    3\n",
       "13  17.3   8  275.8  180  3.07  3.730  17.60  0  0    3\n",
       "14  15.2   8  275.8  180  3.07  3.780  18.00  0  0    3\n",
       "15  10.4   8  472.0  205  2.93  5.250  17.98  0  0    3\n",
       "16  10.4   8  460.0  215  3.00  5.424  17.82  0  0    3\n",
       "17  14.7   8  440.0  230  3.23  5.345  17.42  0  0    3\n",
       "18  32.4   4   78.7   66  4.08  2.200  19.47  1  1    4\n",
       "19  30.4   4   75.7   52  4.93  1.615  18.52  1  1    4\n",
       "20  33.9   4   71.1   65  4.22  1.835  19.90  1  1    4\n",
       "21  21.5   4  120.1   97  3.70  2.465  20.01  1  0    3\n",
       "22  15.5   8  318.0  150  2.76  3.520  16.87  0  0    3\n",
       "23  15.2   8  304.0  150  3.15  3.435  17.30  0  0    3\n",
       "24  13.3   8  350.0  245  3.73  3.840  15.41  0  0    3\n",
       "25  19.2   8  400.0  175  3.08  3.845  17.05  0  0    3\n",
       "26  27.3   4   79.0   66  4.08  1.935  18.90  1  1    4\n",
       "27  26.0   4  120.3   91  4.43  2.140  16.70  0  1    5\n",
       "28  30.4   4   95.1  113  3.77  1.513  16.90  1  1    5\n",
       "29  15.8   8  351.0  264  4.22  3.170  14.50  0  1    5\n",
       "30  19.7   6  145.0  175  3.62  2.770  15.50  0  1    5\n",
       "31  15.0   8  301.0  335  3.54  3.570  14.60  0  1    5"
      ],
      "text/html": [
       "\n",
       "  <div id=\"df-c5eca906-f4ba-4e2a-9db1-5ec94fbfac16\">\n",
       "    <div class=\"colab-df-container\">\n",
       "      <div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mpg</th>\n",
       "      <th>cyl</th>\n",
       "      <th>disp</th>\n",
       "      <th>hp</th>\n",
       "      <th>drat</th>\n",
       "      <th>wt</th>\n",
       "      <th>qsec</th>\n",
       "      <th>vs</th>\n",
       "      <th>am</th>\n",
       "      <th>gear</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>21.0</td>\n",
       "      <td>6</td>\n",
       "      <td>160.0</td>\n",
       "      <td>110</td>\n",
       "      <td>3.90</td>\n",
       "      <td>2.620</td>\n",
       "      <td>16.46</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>21.0</td>\n",
       "      <td>6</td>\n",
       "      <td>160.0</td>\n",
       "      <td>110</td>\n",
       "      <td>3.90</td>\n",
       "      <td>2.875</td>\n",
       "      <td>17.02</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>22.8</td>\n",
       "      <td>4</td>\n",
       "      <td>108.0</td>\n",
       "      <td>93</td>\n",
       "      <td>3.85</td>\n",
       "      <td>2.320</td>\n",
       "      <td>18.61</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>21.4</td>\n",
       "      <td>6</td>\n",
       "      <td>258.0</td>\n",
       "      <td>110</td>\n",
       "      <td>3.08</td>\n",
       "      <td>3.215</td>\n",
       "      <td>19.44</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>18.7</td>\n",
       "      <td>8</td>\n",
       "      <td>360.0</td>\n",
       "      <td>175</td>\n",
       "      <td>3.15</td>\n",
       "      <td>3.440</td>\n",
       "      <td>17.02</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>18.1</td>\n",
       "      <td>6</td>\n",
       "      <td>225.0</td>\n",
       "      <td>105</td>\n",
       "      <td>2.76</td>\n",
       "      <td>3.460</td>\n",
       "      <td>20.22</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>14.3</td>\n",
       "      <td>8</td>\n",
       "      <td>360.0</td>\n",
       "      <td>245</td>\n",
       "      <td>3.21</td>\n",
       "      <td>3.570</td>\n",
       "      <td>15.84</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>24.4</td>\n",
       "      <td>4</td>\n",
       "      <td>146.7</td>\n",
       "      <td>62</td>\n",
       "      <td>3.69</td>\n",
       "      <td>3.190</td>\n",
       "      <td>20.00</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>22.8</td>\n",
       "      <td>4</td>\n",
       "      <td>140.8</td>\n",
       "      <td>95</td>\n",
       "      <td>3.92</td>\n",
       "      <td>3.150</td>\n",
       "      <td>22.90</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>19.2</td>\n",
       "      <td>6</td>\n",
       "      <td>167.6</td>\n",
       "      <td>123</td>\n",
       "      <td>3.92</td>\n",
       "      <td>3.440</td>\n",
       "      <td>18.30</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>17.8</td>\n",
       "      <td>6</td>\n",
       "      <td>167.6</td>\n",
       "      <td>123</td>\n",
       "      <td>3.92</td>\n",
       "      <td>3.440</td>\n",
       "      <td>18.90</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>16.4</td>\n",
       "      <td>8</td>\n",
       "      <td>275.8</td>\n",
       "      <td>180</td>\n",
       "      <td>3.07</td>\n",
       "      <td>4.070</td>\n",
       "      <td>17.40</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>17.3</td>\n",
       "      <td>8</td>\n",
       "      <td>275.8</td>\n",
       "      <td>180</td>\n",
       "      <td>3.07</td>\n",
       "      <td>3.730</td>\n",
       "      <td>17.60</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15.2</td>\n",
       "      <td>8</td>\n",
       "      <td>275.8</td>\n",
       "      <td>180</td>\n",
       "      <td>3.07</td>\n",
       "      <td>3.780</td>\n",
       "      <td>18.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>10.4</td>\n",
       "      <td>8</td>\n",
       "      <td>472.0</td>\n",
       "      <td>205</td>\n",
       "      <td>2.93</td>\n",
       "      <td>5.250</td>\n",
       "      <td>17.98</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>10.4</td>\n",
       "      <td>8</td>\n",
       "      <td>460.0</td>\n",
       "      <td>215</td>\n",
       "      <td>3.00</td>\n",
       "      <td>5.424</td>\n",
       "      <td>17.82</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>14.7</td>\n",
       "      <td>8</td>\n",
       "      <td>440.0</td>\n",
       "      <td>230</td>\n",
       "      <td>3.23</td>\n",
       "      <td>5.345</td>\n",
       "      <td>17.42</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>32.4</td>\n",
       "      <td>4</td>\n",
       "      <td>78.7</td>\n",
       "      <td>66</td>\n",
       "      <td>4.08</td>\n",
       "      <td>2.200</td>\n",
       "      <td>19.47</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>30.4</td>\n",
       "      <td>4</td>\n",
       "      <td>75.7</td>\n",
       "      <td>52</td>\n",
       "      <td>4.93</td>\n",
       "      <td>1.615</td>\n",
       "      <td>18.52</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>33.9</td>\n",
       "      <td>4</td>\n",
       "      <td>71.1</td>\n",
       "      <td>65</td>\n",
       "      <td>4.22</td>\n",
       "      <td>1.835</td>\n",
       "      <td>19.90</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>21.5</td>\n",
       "      <td>4</td>\n",
       "      <td>120.1</td>\n",
       "      <td>97</td>\n",
       "      <td>3.70</td>\n",
       "      <td>2.465</td>\n",
       "      <td>20.01</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>15.5</td>\n",
       "      <td>8</td>\n",
       "      <td>318.0</td>\n",
       "      <td>150</td>\n",
       "      <td>2.76</td>\n",
       "      <td>3.520</td>\n",
       "      <td>16.87</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>15.2</td>\n",
       "      <td>8</td>\n",
       "      <td>304.0</td>\n",
       "      <td>150</td>\n",
       "      <td>3.15</td>\n",
       "      <td>3.435</td>\n",
       "      <td>17.30</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>13.3</td>\n",
       "      <td>8</td>\n",
       "      <td>350.0</td>\n",
       "      <td>245</td>\n",
       "      <td>3.73</td>\n",
       "      <td>3.840</td>\n",
       "      <td>15.41</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>19.2</td>\n",
       "      <td>8</td>\n",
       "      <td>400.0</td>\n",
       "      <td>175</td>\n",
       "      <td>3.08</td>\n",
       "      <td>3.845</td>\n",
       "      <td>17.05</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27.3</td>\n",
       "      <td>4</td>\n",
       "      <td>79.0</td>\n",
       "      <td>66</td>\n",
       "      <td>4.08</td>\n",
       "      <td>1.935</td>\n",
       "      <td>18.90</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>26.0</td>\n",
       "      <td>4</td>\n",
       "      <td>120.3</td>\n",
       "      <td>91</td>\n",
       "      <td>4.43</td>\n",
       "      <td>2.140</td>\n",
       "      <td>16.70</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>30.4</td>\n",
       "      <td>4</td>\n",
       "      <td>95.1</td>\n",
       "      <td>113</td>\n",
       "      <td>3.77</td>\n",
       "      <td>1.513</td>\n",
       "      <td>16.90</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>15.8</td>\n",
       "      <td>8</td>\n",
       "      <td>351.0</td>\n",
       "      <td>264</td>\n",
       "      <td>4.22</td>\n",
       "      <td>3.170</td>\n",
       "      <td>14.50</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>19.7</td>\n",
       "      <td>6</td>\n",
       "      <td>145.0</td>\n",
       "      <td>175</td>\n",
       "      <td>3.62</td>\n",
       "      <td>2.770</td>\n",
       "      <td>15.50</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>15.0</td>\n",
       "      <td>8</td>\n",
       "      <td>301.0</td>\n",
       "      <td>335</td>\n",
       "      <td>3.54</td>\n",
       "      <td>3.570</td>\n",
       "      <td>14.60</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>\n",
       "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-c5eca906-f4ba-4e2a-9db1-5ec94fbfac16')\"\n",
       "              title=\"Convert this dataframe to an interactive table.\"\n",
       "              style=\"display:none;\">\n",
       "        \n",
       "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
       "       width=\"24px\">\n",
       "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
       "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
       "  </svg>\n",
       "      </button>\n",
       "      \n",
       "  <style>\n",
       "    .colab-df-container {\n",
       "      display:flex;\n",
       "      flex-wrap:wrap;\n",
       "      gap: 12px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert {\n",
       "      background-color: #E8F0FE;\n",
       "      border: none;\n",
       "      border-radius: 50%;\n",
       "      cursor: pointer;\n",
       "      display: none;\n",
       "      fill: #1967D2;\n",
       "      height: 32px;\n",
       "      padding: 0 0 0 0;\n",
       "      width: 32px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert:hover {\n",
       "      background-color: #E2EBFA;\n",
       "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "      fill: #174EA6;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert {\n",
       "      background-color: #3B4455;\n",
       "      fill: #D2E3FC;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert:hover {\n",
       "      background-color: #434B5C;\n",
       "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
       "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
       "      fill: #FFFFFF;\n",
       "    }\n",
       "  </style>\n",
       "\n",
       "      <script>\n",
       "        const buttonEl =\n",
       "          document.querySelector('#df-c5eca906-f4ba-4e2a-9db1-5ec94fbfac16 button.colab-df-convert');\n",
       "        buttonEl.style.display =\n",
       "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "\n",
       "        async function convertToInteractive(key) {\n",
       "          const element = document.querySelector('#df-c5eca906-f4ba-4e2a-9db1-5ec94fbfac16');\n",
       "          const dataTable =\n",
       "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
       "                                                     [key], {});\n",
       "          if (!dataTable) return;\n",
       "\n",
       "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
       "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
       "            + ' to learn more about interactive tables.';\n",
       "          element.innerHTML = '';\n",
       "          dataTable['output_type'] = 'display_data';\n",
       "          await google.colab.output.renderOutput(dataTable, element);\n",
       "          const docLink = document.createElement('div');\n",
       "          docLink.innerHTML = docLinkHtml;\n",
       "          element.appendChild(docLink);\n",
       "        }\n",
       "      </script>\n",
       "    </div>\n",
       "  </div>\n",
       "  "
      ]
     },
     "metadata": {},
     "execution_count": 20
    }
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "results[1]"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 488
    },
    "id": "h6dI6IQRB9RR",
    "outputId": "8d18bb70-ba8a-445f-a627-c790fe0d0b91",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 21,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "   Sepal.Length Sepal.Width Petal.Length   Petal.Width      Species           \n",
       "1                       5.1          3.5           1.4   0.2 setosa           \n",
       "2                       4.9          3.0           1.4   0.2 setosa           \n",
       "3                       4.7          3.2           1.3   0.2 setosa           \n",
       "4                       4.6          3.1           1.5   0.2 setosa           \n",
       "5                       5.0          3.6           1.4   0.2 setosa           \n",
       "6                       5.4          3.9           1.7   0.4 setosa           \n",
       "7              Sepal.Length  Sepal.Width  Petal.Length  Petal.Width    Species\n",
       "8                   145 6.7          3.3           5.7          2.5  virginica\n",
       "9                   146 6.7          3.0           5.2          2.3  virginica\n",
       "10                  147 6.3          2.5           5.0          1.9  virginica\n",
       "11                  148 6.5          3.0           5.2          2.0  virginica\n",
       "12                  149 6.2          3.4           5.4          2.3  virginica\n",
       "13                  150 5.9          3.0           5.1          1.8  virginica\n",
       "14                                     2                                      "
      ],
      "text/html": [
       "\n",
       "  <div id=\"df-99bf5ce2-b13f-46dd-9983-4e6e21fc389d\">\n",
       "    <div class=\"colab-df-container\">\n",
       "      <div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Sepal.Length Sepal.Width</th>\n",
       "      <th>Petal.Length</th>\n",
       "      <th>Petal.Width</th>\n",
       "      <th>Species</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5.1</td>\n",
       "      <td>3.5</td>\n",
       "      <td>1.4</td>\n",
       "      <td>0.2 setosa</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4.9</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.4</td>\n",
       "      <td>0.2 setosa</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4.7</td>\n",
       "      <td>3.2</td>\n",
       "      <td>1.3</td>\n",
       "      <td>0.2 setosa</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4.6</td>\n",
       "      <td>3.1</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.2 setosa</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5.0</td>\n",
       "      <td>3.6</td>\n",
       "      <td>1.4</td>\n",
       "      <td>0.2 setosa</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>5.4</td>\n",
       "      <td>3.9</td>\n",
       "      <td>1.7</td>\n",
       "      <td>0.4 setosa</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Sepal.Length</td>\n",
       "      <td>Sepal.Width</td>\n",
       "      <td>Petal.Length</td>\n",
       "      <td>Petal.Width</td>\n",
       "      <td>Species</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>145 6.7</td>\n",
       "      <td>3.3</td>\n",
       "      <td>5.7</td>\n",
       "      <td>2.5</td>\n",
       "      <td>virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>146 6.7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.2</td>\n",
       "      <td>2.3</td>\n",
       "      <td>virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>147 6.3</td>\n",
       "      <td>2.5</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.9</td>\n",
       "      <td>virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>148 6.5</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.2</td>\n",
       "      <td>2.0</td>\n",
       "      <td>virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>149 6.2</td>\n",
       "      <td>3.4</td>\n",
       "      <td>5.4</td>\n",
       "      <td>2.3</td>\n",
       "      <td>virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>150 5.9</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.1</td>\n",
       "      <td>1.8</td>\n",
       "      <td>virginica</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td></td>\n",
       "      <td>2</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>\n",
       "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-99bf5ce2-b13f-46dd-9983-4e6e21fc389d')\"\n",
       "              title=\"Convert this dataframe to an interactive table.\"\n",
       "              style=\"display:none;\">\n",
       "        \n",
       "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
       "       width=\"24px\">\n",
       "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
       "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
       "  </svg>\n",
       "      </button>\n",
       "      \n",
       "  <style>\n",
       "    .colab-df-container {\n",
       "      display:flex;\n",
       "      flex-wrap:wrap;\n",
       "      gap: 12px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert {\n",
       "      background-color: #E8F0FE;\n",
       "      border: none;\n",
       "      border-radius: 50%;\n",
       "      cursor: pointer;\n",
       "      display: none;\n",
       "      fill: #1967D2;\n",
       "      height: 32px;\n",
       "      padding: 0 0 0 0;\n",
       "      width: 32px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert:hover {\n",
       "      background-color: #E2EBFA;\n",
       "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "      fill: #174EA6;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert {\n",
       "      background-color: #3B4455;\n",
       "      fill: #D2E3FC;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert:hover {\n",
       "      background-color: #434B5C;\n",
       "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
       "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
       "      fill: #FFFFFF;\n",
       "    }\n",
       "  </style>\n",
       "\n",
       "      <script>\n",
       "        const buttonEl =\n",
       "          document.querySelector('#df-99bf5ce2-b13f-46dd-9983-4e6e21fc389d button.colab-df-convert');\n",
       "        buttonEl.style.display =\n",
       "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "\n",
       "        async function convertToInteractive(key) {\n",
       "          const element = document.querySelector('#df-99bf5ce2-b13f-46dd-9983-4e6e21fc389d');\n",
       "          const dataTable =\n",
       "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
       "                                                     [key], {});\n",
       "          if (!dataTable) return;\n",
       "\n",
       "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
       "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
       "            + ' to learn more about interactive tables.';\n",
       "          element.innerHTML = '';\n",
       "          dataTable['output_type'] = 'display_data';\n",
       "          await google.colab.output.renderOutput(dataTable, element);\n",
       "          const docLink = document.createElement('div');\n",
       "          docLink.innerHTML = docLinkHtml;\n",
       "          element.appendChild(docLink);\n",
       "        }\n",
       "      </script>\n",
       "    </div>\n",
       "  </div>\n",
       "  "
      ]
     },
     "metadata": {},
     "execution_count": 21
    }
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "results[2]"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 488
    },
    "id": "8ssgqw20B9pt",
    "outputId": "e866f806-77c6-47f7-e776-177b8ec42dc8",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 22,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "   supp\n",
       "1    VC\n",
       "2    VC\n",
       "3    VC\n",
       "4    VC\n",
       "5    VC\n",
       "6    VC\n",
       "7    VC\n",
       "8    VC\n",
       "9    VC\n",
       "10   VC\n",
       "11   VC\n",
       "12   VC\n",
       "13   VC\n",
       "14   VC"
      ],
      "text/html": [
       "\n",
       "  <div id=\"df-50cb9263-6907-4586-8244-0f605e9b8969\">\n",
       "    <div class=\"colab-df-container\">\n",
       "      <div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>supp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>VC</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>\n",
       "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-50cb9263-6907-4586-8244-0f605e9b8969')\"\n",
       "              title=\"Convert this dataframe to an interactive table.\"\n",
       "              style=\"display:none;\">\n",
       "        \n",
       "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
       "       width=\"24px\">\n",
       "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
       "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
       "  </svg>\n",
       "      </button>\n",
       "      \n",
       "  <style>\n",
       "    .colab-df-container {\n",
       "      display:flex;\n",
       "      flex-wrap:wrap;\n",
       "      gap: 12px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert {\n",
       "      background-color: #E8F0FE;\n",
       "      border: none;\n",
       "      border-radius: 50%;\n",
       "      cursor: pointer;\n",
       "      display: none;\n",
       "      fill: #1967D2;\n",
       "      height: 32px;\n",
       "      padding: 0 0 0 0;\n",
       "      width: 32px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert:hover {\n",
       "      background-color: #E2EBFA;\n",
       "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "      fill: #174EA6;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert {\n",
       "      background-color: #3B4455;\n",
       "      fill: #D2E3FC;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert:hover {\n",
       "      background-color: #434B5C;\n",
       "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
       "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
       "      fill: #FFFFFF;\n",
       "    }\n",
       "  </style>\n",
       "\n",
       "      <script>\n",
       "        const buttonEl =\n",
       "          document.querySelector('#df-50cb9263-6907-4586-8244-0f605e9b8969 button.colab-df-convert');\n",
       "        buttonEl.style.display =\n",
       "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "\n",
       "        async function convertToInteractive(key) {\n",
       "          const element = document.querySelector('#df-50cb9263-6907-4586-8244-0f605e9b8969');\n",
       "          const dataTable =\n",
       "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
       "                                                     [key], {});\n",
       "          if (!dataTable) return;\n",
       "\n",
       "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
       "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
       "            + ' to learn more about interactive tables.';\n",
       "          element.innerHTML = '';\n",
       "          dataTable['output_type'] = 'display_data';\n",
       "          await google.colab.output.renderOutput(dataTable, element);\n",
       "          const docLink = document.createElement('div');\n",
       "          docLink.innerHTML = docLinkHtml;\n",
       "          element.appendChild(docLink);\n",
       "        }\n",
       "      </script>\n",
       "    </div>\n",
       "  </div>\n",
       "  "
      ]
     },
     "metadata": {},
     "execution_count": 22
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Run the `pdf2table` spell on more complex pdf file\n",
    "Here we have a real pdf file with 8 tables. Lets run `pdf2table` spell on it!"
   ],
   "metadata": {
    "id": "O57g3TUSgsCI",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "results = nlp.load('pdf2table').predict('/content/insurance.pdf')\n",
    "print_tables(results)"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "AKpCECVwhBFi",
    "outputId": "41750038-cd2d-41d3-d7c5-0e99ca7b289c",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 5,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Table 1:\n",
      "  0_ Volume/\\rModel #                                 Title of Model  \\\n",
      "1             III-360            Consumer Credit Insurance Model Act   \n",
      "2             III-365  Credit Personal Property Insurance Model\\rAct   \n",
      "3             III-370    Consumer Credit Insurance Model\\rRegulation   \n",
      "4             III-375            Creditor-Placed Insurance Model Act   \n",
      "\n",
      "                                         Description  \\\n",
      "1  This model act helps promote the public welfar...   \n",
      "2  This model act 1) Promotes the public welfare ...   \n",
      "3  This model regulation helps protect the intere...   \n",
      "4  This model act creates a legal framework withi...   \n",
      "\n",
      "  Related Charts: State Laws on Insurance Topics 5_  \n",
      "1                                                    \n",
      "2                                                    \n",
      "3      PC-50 - Terrorism and War Risks Exclusion     \n",
      "4                                                    \n",
      "\n",
      "\n",
      "Table 2:\n",
      "  0_  III-385  \\\n",
      "1     III-390   \n",
      "2     III-395   \n",
      "\n",
      "  Model Regulation to Define Standards and\\rCommissioner’s Authority for Companies\\rDeemed to be in Hazardous Financial\\rCondition  \\\n",
      "1                          Model Law on Examinations                                                                                 \n",
      "2  Participation in the NAIC Insurance\\rRegulator...                                                                                 \n",
      "\n",
      "  This model regulation sets forth standards for identifying insurers found to be in such\\rcondition as to render the continuance of their business hazardous to the public or to\\rholders of their policies or certificates of insurance.  \\\n",
      "1  This model law helps provide an effective, eff...                                                                                                                                                                                         \n",
      "2  This model act sets forth the requirements for...                                                                                                                                                                                         \n",
      "\n",
      "                                                  4_ 5_  \n",
      "1  CF-40 - Financial Examinations Standards for I...     \n",
      "2                                                        \n",
      "\n",
      "\n",
      "Table 3:\n",
      "  0_  III-430         Health Maintenance Organization Model\\rAct  \\\n",
      "1     III-432  Model Regulation to Implement Rules\\rRegarding...   \n",
      "\n",
      "  This model act provides for a system of regulation for health maintenance organizations\\rthat is fair and efficient, and promotes the continued solvency of health maintenance\\rorganizations.  \\\n",
      "1  This model regulation implements the NAIC Heal...                                                                                                                                               \n",
      "\n",
      "  HM-10 - Departmental Regulation of HMOs\\rHM-20 - Open Enrollment Periods for HMOs\\rHM-30 - HMO Net Worth and Deposit Requirements  \\\n",
      "1  HM-10 - Departmental Regulation of HMOs\\rHM-20...                                                                                  \n",
      "\n",
      "  5_  \n",
      "1     \n",
      "\n",
      "\n",
      "Table 4:\n",
      "  0_ Volume/\\rModel #                                     Title of Model  \\\n",
      "1             III-440   Insurance Holding Company System\\rRegulatory Act   \n",
      "2             III-450  Insurance Holding Company System Model\\rRegula...   \n",
      "\n",
      "                                         Description  \\\n",
      "1  This model act includes requirements pertainin...   \n",
      "2  This model regulation sets forth rules and pro...   \n",
      "\n",
      "  Related Charts: State Laws on Insurance Topics 5_  \n",
      "1                                                    \n",
      "2                                                    \n",
      "\n",
      "\n",
      "Table 5:\n",
      "  0_  III-460  \\\n",
      "1     III-480   \n",
      "2     III-490   \n",
      "3     III-500   \n",
      "\n",
      "  An Act Concerning Insider Trading of\\rDomestic Stock Insurance Company Equity\\rSecurities  \\\n",
      "1  Regulations Adopted Pursuant to an Act\\rConcer...                                          \n",
      "2  Regulation Regarding Proxies, Consents\\rand Au...                                          \n",
      "3  Stockholders Information Supplement\\rSchedule SIS                                          \n",
      "\n",
      "  This model act includes provisions concerning the unfair use of information, sales of\\requity security, exceptions, definitions and forfeiture. Its corresponding model regulation\\ris MDL-480.  \\\n",
      "1  This model regulation contains definitions and...                                                                                                                                                \n",
      "2  Thismodelregulationprovidesproxyrequirements,f...                                                                                                                                                \n",
      "3  This model contains general instructions, info...                                                                                                                                                \n",
      "\n",
      "  4_ 5_  \n",
      "1        \n",
      "2        \n",
      "3        \n",
      "\n",
      "\n",
      "Table 6:\n",
      "  0_  III-505  \\\n",
      "1     III-510   \n",
      "2     III-520   \n",
      "\n",
      "  Risk Management and Own Risk and\\rSolvency Assessment (ORSA) Model Act  \\\n",
      "1  Criminal Sanctions for Failure to Report\\rImpa...                       \n",
      "2  Life and Health Insurance Guaranty\\rAssociatio...                       \n",
      "\n",
      "  Thismodelactestablishestherequirementsformaintainingariskmanagement\\rframework and completing an Own Risk and Solvency Assessment (ORSA). It addresses\\rexemptions, confidentiality and sanctions.  \\\n",
      "1  This model outlines the criminal sanctions and...                                                                                                                                                   \n",
      "2  This model act protects against failure in the...                                                                                                                                                   \n",
      "\n",
      "                                                  4_ 5_  \n",
      "1                                                        \n",
      "2  IN-10 - Life and Health Guaranty Fund Laws\\rIN...     \n",
      "\n",
      "\n",
      "Table 7:\n",
      "  0_ Volume/\\rModel #                                     Title of Model  \\\n",
      "1             III-540  Property and Casualty Insurance Guaranty\\rAsso...   \n",
      "2             III-555                     Insurer Receivership Model Act   \n",
      "3             III-558               Administrative Supervision Model Act   \n",
      "\n",
      "                                         Description  \\\n",
      "1  This model act provides a mechanism for the pa...   \n",
      "2  This model act helps protect the interests of ...   \n",
      "3  This model act outlines the parameters under w...   \n",
      "\n",
      "      Related Charts: State Laws on Insurance Topics 5_  \n",
      "1  IN-30 - Property and Casualty Guaranty Fund La...     \n",
      "2                                                        \n",
      "3                                                        \n",
      "\n",
      "\n",
      "Table 8:\n",
      "  0_  IV-565  \\\n",
      "1     IV-568   \n",
      "2     IV-570   \n",
      "3     IV-575   \n",
      "4     IV-580   \n",
      "\n",
      "  Group Life Insurance Definition and Group\\rLife Insurance Standard Provisions Model\\rAct  \\\n",
      "1          Military Sales Practices Model Regulation                                         \n",
      "2  Advertisements of Life Insurance and\\rAnnuitie...                                         \n",
      "3  Life and Health Insurance Policy Language\\rSim...                                         \n",
      "4         Life Insurance Disclosure Model Regulation                                         \n",
      "\n",
      "  This model act sets forth group life insurance standard provisions. It defines group life\\rinsurance and contains provisions relating to limits of group life insurance, notice of\\rcompensation, dependent coverage, standard provisions, and a supplementary provision\\rrelating to conversion privileges.  \\\n",
      "1  The purpose of this model regulation is to set...                                                                                                                                                                                                                                                             \n",
      "2  This model regulation sets forth minimum stand...                                                                                                                                                                                                                                                             \n",
      "3  This model act establishes minimum standards f...                                                                                                                                                                                                                                                             \n",
      "4  This model regulation requires insurers to pro...                                                                                                                                                                                                                                                             \n",
      "\n",
      "                                                  4_ 5_  \n",
      "1          PC-50 - Terrorism and War Risks Exclusion     \n",
      "2       LI-30 - Life Insurance Disclosure Provisions     \n",
      "3  LI-20 - Form Filing Requirements Life Insuranc...     \n",
      "4  LI-30 - Life Insurance Disclosure Provisions\\r...     \n",
      "\n",
      "\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Table extraction examples with alternativy input types"
   ],
   "metadata": {
    "id": "rE1sjQdyPfnU",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Predict on array of paths"
   ],
   "metadata": {
    "id": "CE24p1VEPi5H",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "pdf_paths = ['/content/tables.pdf','/content/insurance.pdf',]\n",
    "results = nlp.load('pdf2table' ).predict(pdf_paths)\n",
    "print_tables(results)"
   ],
   "metadata": {
    "id": "gsQsncxsPdyi",
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "outputId": "e54b35fe-f056-4b47-c5b6-f41f80552a37",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 6,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Table 1:\n",
      "  0_ Volume/\\rModel #                                 Title of Model  \\\n",
      "1             III-360            Consumer Credit Insurance Model Act   \n",
      "2             III-365  Credit Personal Property Insurance Model\\rAct   \n",
      "3             III-370    Consumer Credit Insurance Model\\rRegulation   \n",
      "4             III-375            Creditor-Placed Insurance Model Act   \n",
      "\n",
      "                                         Description  \\\n",
      "1  This model act helps promote the public welfar...   \n",
      "2  This model act 1) Promotes the public welfare ...   \n",
      "3  This model regulation helps protect the intere...   \n",
      "4  This model act creates a legal framework withi...   \n",
      "\n",
      "  Related Charts: State Laws on Insurance Topics 5_  \n",
      "1                                                    \n",
      "2                                                    \n",
      "3      PC-50 - Terrorism and War Risks Exclusion     \n",
      "4                                                    \n",
      "\n",
      "\n",
      "Table 2:\n",
      "  0_  III-385  \\\n",
      "1     III-390   \n",
      "2     III-395   \n",
      "\n",
      "  Model Regulation to Define Standards and\\rCommissioner’s Authority for Companies\\rDeemed to be in Hazardous Financial\\rCondition  \\\n",
      "1                          Model Law on Examinations                                                                                 \n",
      "2  Participation in the NAIC Insurance\\rRegulator...                                                                                 \n",
      "\n",
      "  This model regulation sets forth standards for identifying insurers found to be in such\\rcondition as to render the continuance of their business hazardous to the public or to\\rholders of their policies or certificates of insurance.  \\\n",
      "1  This model law helps provide an effective, eff...                                                                                                                                                                                         \n",
      "2  This model act sets forth the requirements for...                                                                                                                                                                                         \n",
      "\n",
      "                                                  4_ 5_  \n",
      "1  CF-40 - Financial Examinations Standards for I...     \n",
      "2                                                        \n",
      "\n",
      "\n",
      "Table 3:\n",
      "  0_  III-430         Health Maintenance Organization Model\\rAct  \\\n",
      "1     III-432  Model Regulation to Implement Rules\\rRegarding...   \n",
      "\n",
      "  This model act provides for a system of regulation for health maintenance organizations\\rthat is fair and efficient, and promotes the continued solvency of health maintenance\\rorganizations.  \\\n",
      "1  This model regulation implements the NAIC Heal...                                                                                                                                               \n",
      "\n",
      "  HM-10 - Departmental Regulation of HMOs\\rHM-20 - Open Enrollment Periods for HMOs\\rHM-30 - HMO Net Worth and Deposit Requirements  \\\n",
      "1  HM-10 - Departmental Regulation of HMOs\\rHM-20...                                                                                  \n",
      "\n",
      "  5_  \n",
      "1     \n",
      "\n",
      "\n",
      "Table 4:\n",
      "  0_ Volume/\\rModel #                                     Title of Model  \\\n",
      "1             III-440   Insurance Holding Company System\\rRegulatory Act   \n",
      "2             III-450  Insurance Holding Company System Model\\rRegula...   \n",
      "\n",
      "                                         Description  \\\n",
      "1  This model act includes requirements pertainin...   \n",
      "2  This model regulation sets forth rules and pro...   \n",
      "\n",
      "  Related Charts: State Laws on Insurance Topics 5_  \n",
      "1                                                    \n",
      "2                                                    \n",
      "\n",
      "\n",
      "Table 5:\n",
      "  0_  III-460  \\\n",
      "1     III-480   \n",
      "2     III-490   \n",
      "3     III-500   \n",
      "\n",
      "  An Act Concerning Insider Trading of\\rDomestic Stock Insurance Company Equity\\rSecurities  \\\n",
      "1  Regulations Adopted Pursuant to an Act\\rConcer...                                          \n",
      "2  Regulation Regarding Proxies, Consents\\rand Au...                                          \n",
      "3  Stockholders Information Supplement\\rSchedule SIS                                          \n",
      "\n",
      "  This model act includes provisions concerning the unfair use of information, sales of\\requity security, exceptions, definitions and forfeiture. Its corresponding model regulation\\ris MDL-480.  \\\n",
      "1  This model regulation contains definitions and...                                                                                                                                                \n",
      "2  Thismodelregulationprovidesproxyrequirements,f...                                                                                                                                                \n",
      "3  This model contains general instructions, info...                                                                                                                                                \n",
      "\n",
      "  4_ 5_  \n",
      "1        \n",
      "2        \n",
      "3        \n",
      "\n",
      "\n",
      "Table 6:\n",
      "  0_  III-505  \\\n",
      "1     III-510   \n",
      "2     III-520   \n",
      "\n",
      "  Risk Management and Own Risk and\\rSolvency Assessment (ORSA) Model Act  \\\n",
      "1  Criminal Sanctions for Failure to Report\\rImpa...                       \n",
      "2  Life and Health Insurance Guaranty\\rAssociatio...                       \n",
      "\n",
      "  Thismodelactestablishestherequirementsformaintainingariskmanagement\\rframework and completing an Own Risk and Solvency Assessment (ORSA). It addresses\\rexemptions, confidentiality and sanctions.  \\\n",
      "1  This model outlines the criminal sanctions and...                                                                                                                                                   \n",
      "2  This model act protects against failure in the...                                                                                                                                                   \n",
      "\n",
      "                                                  4_ 5_  \n",
      "1                                                        \n",
      "2  IN-10 - Life and Health Guaranty Fund Laws\\rIN...     \n",
      "\n",
      "\n",
      "Table 7:\n",
      "  0_ Volume/\\rModel #                                     Title of Model  \\\n",
      "1             III-540  Property and Casualty Insurance Guaranty\\rAsso...   \n",
      "2             III-555                     Insurer Receivership Model Act   \n",
      "3             III-558               Administrative Supervision Model Act   \n",
      "\n",
      "                                         Description  \\\n",
      "1  This model act provides a mechanism for the pa...   \n",
      "2  This model act helps protect the interests of ...   \n",
      "3  This model act outlines the parameters under w...   \n",
      "\n",
      "      Related Charts: State Laws on Insurance Topics 5_  \n",
      "1  IN-30 - Property and Casualty Guaranty Fund La...     \n",
      "2                                                        \n",
      "3                                                        \n",
      "\n",
      "\n",
      "Table 8:\n",
      "  0_  IV-565  \\\n",
      "1     IV-568   \n",
      "2     IV-570   \n",
      "3     IV-575   \n",
      "4     IV-580   \n",
      "\n",
      "  Group Life Insurance Definition and Group\\rLife Insurance Standard Provisions Model\\rAct  \\\n",
      "1          Military Sales Practices Model Regulation                                         \n",
      "2  Advertisements of Life Insurance and\\rAnnuitie...                                         \n",
      "3  Life and Health Insurance Policy Language\\rSim...                                         \n",
      "4         Life Insurance Disclosure Model Regulation                                         \n",
      "\n",
      "  This model act sets forth group life insurance standard provisions. It defines group life\\rinsurance and contains provisions relating to limits of group life insurance, notice of\\rcompensation, dependent coverage, standard provisions, and a supplementary provision\\rrelating to conversion privileges.  \\\n",
      "1  The purpose of this model regulation is to set...                                                                                                                                                                                                                                                             \n",
      "2  This model regulation sets forth minimum stand...                                                                                                                                                                                                                                                             \n",
      "3  This model act establishes minimum standards f...                                                                                                                                                                                                                                                             \n",
      "4  This model regulation requires insurers to pro...                                                                                                                                                                                                                                                             \n",
      "\n",
      "                                                  4_ 5_  \n",
      "1          PC-50 - Terrorism and War Risks Exclusion     \n",
      "2       LI-30 - Life Insurance Disclosure Provisions     \n",
      "3  LI-20 - Form Filing Requirements Life Insuranc...     \n",
      "4  LI-30 - Life Insurance Disclosure Provisions\\r...     \n",
      "\n",
      "\n",
      "Table 9:\n",
      "     mpg cyl   disp   hp  drat     wt   qsec vs am gear\n",
      "1   21.0   6  160.0  110  3.90  2.620  16.46  0  1    4\n",
      "2   21.0   6  160.0  110  3.90  2.875  17.02  0  1    4\n",
      "3   22.8   4  108.0   93  3.85  2.320  18.61  1  1    4\n",
      "4   21.4   6  258.0  110  3.08  3.215  19.44  1  0    3\n",
      "5   18.7   8  360.0  175  3.15  3.440  17.02  0  0    3\n",
      "6   18.1   6  225.0  105  2.76  3.460  20.22  1  0    3\n",
      "7   14.3   8  360.0  245  3.21  3.570  15.84  0  0    3\n",
      "8   24.4   4  146.7   62  3.69  3.190  20.00  1  0    4\n",
      "9   22.8   4  140.8   95  3.92  3.150  22.90  1  0    4\n",
      "10  19.2   6  167.6  123  3.92  3.440  18.30  1  0    4\n",
      "11  17.8   6  167.6  123  3.92  3.440  18.90  1  0    4\n",
      "12  16.4   8  275.8  180  3.07  4.070  17.40  0  0    3\n",
      "13  17.3   8  275.8  180  3.07  3.730  17.60  0  0    3\n",
      "14  15.2   8  275.8  180  3.07  3.780  18.00  0  0    3\n",
      "15  10.4   8  472.0  205  2.93  5.250  17.98  0  0    3\n",
      "16  10.4   8  460.0  215  3.00  5.424  17.82  0  0    3\n",
      "17  14.7   8  440.0  230  3.23  5.345  17.42  0  0    3\n",
      "18  32.4   4   78.7   66  4.08  2.200  19.47  1  1    4\n",
      "19  30.4   4   75.7   52  4.93  1.615  18.52  1  1    4\n",
      "20  33.9   4   71.1   65  4.22  1.835  19.90  1  1    4\n",
      "21  21.5   4  120.1   97  3.70  2.465  20.01  1  0    3\n",
      "22  15.5   8  318.0  150  2.76  3.520  16.87  0  0    3\n",
      "23  15.2   8  304.0  150  3.15  3.435  17.30  0  0    3\n",
      "24  13.3   8  350.0  245  3.73  3.840  15.41  0  0    3\n",
      "25  19.2   8  400.0  175  3.08  3.845  17.05  0  0    3\n",
      "26  27.3   4   79.0   66  4.08  1.935  18.90  1  1    4\n",
      "27  26.0   4  120.3   91  4.43  2.140  16.70  0  1    5\n",
      "28  30.4   4   95.1  113  3.77  1.513  16.90  1  1    5\n",
      "29  15.8   8  351.0  264  4.22  3.170  14.50  0  1    5\n",
      "30  19.7   6  145.0  175  3.62  2.770  15.50  0  1    5\n",
      "31  15.0   8  301.0  335  3.54  3.570  14.60  0  1    5\n",
      "\n",
      "\n",
      "Table 10:\n",
      "   Sepal.Length Sepal.Width Petal.Length   Petal.Width      Species           \n",
      "1                       5.1          3.5           1.4   0.2 setosa           \n",
      "2                       4.9          3.0           1.4   0.2 setosa           \n",
      "3                       4.7          3.2           1.3   0.2 setosa           \n",
      "4                       4.6          3.1           1.5   0.2 setosa           \n",
      "5                       5.0          3.6           1.4   0.2 setosa           \n",
      "6                       5.4          3.9           1.7   0.4 setosa           \n",
      "7              Sepal.Length  Sepal.Width  Petal.Length  Petal.Width    Species\n",
      "8                   145 6.7          3.3           5.7          2.5  virginica\n",
      "9                   146 6.7          3.0           5.2          2.3  virginica\n",
      "10                  147 6.3          2.5           5.0          1.9  virginica\n",
      "11                  148 6.5          3.0           5.2          2.0  virginica\n",
      "12                  149 6.2          3.4           5.4          2.3  virginica\n",
      "13                  150 5.9          3.0           5.1          1.8  virginica\n",
      "14                                     2                                      \n",
      "\n",
      "\n",
      "Table 11:\n",
      "   supp\n",
      "1    VC\n",
      "2    VC\n",
      "3    VC\n",
      "4    VC\n",
      "5    VC\n",
      "6    VC\n",
      "7    VC\n",
      "8    VC\n",
      "9    VC\n",
      "10   VC\n",
      "11   VC\n",
      "12   VC\n",
      "13   VC\n",
      "14   VC\n",
      "\n",
      "\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Predict on dataframe containing a `path` column"
   ],
   "metadata": {
    "id": "YHN6gJlgPn7r",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "# create a dataframe with paths\n",
    "import pandas as pd \n",
    "\n",
    "pdf_paths = ['/content/tables.pdf','/content/insurance.pdf',]\n",
    "df = pd.DataFrame({'path':pdf_paths})\n",
    "df"
   ],
   "metadata": {
    "id": "e3FIHf28PfNY",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 112
    },
    "outputId": "4cf5af15-c915-4393-9299-4bf71c385b3c",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 7,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "                     path\n",
       "0     /content/tables.pdf\n",
       "1  /content/insurance.pdf"
      ],
      "text/html": [
       "\n",
       "  <div id=\"df-b96b78f7-abe0-4680-8e76-08bb69674a58\">\n",
       "    <div class=\"colab-df-container\">\n",
       "      <div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>path</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>/content/tables.pdf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>/content/insurance.pdf</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>\n",
       "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-b96b78f7-abe0-4680-8e76-08bb69674a58')\"\n",
       "              title=\"Convert this dataframe to an interactive table.\"\n",
       "              style=\"display:none;\">\n",
       "        \n",
       "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
       "       width=\"24px\">\n",
       "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
       "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
       "  </svg>\n",
       "      </button>\n",
       "      \n",
       "  <style>\n",
       "    .colab-df-container {\n",
       "      display:flex;\n",
       "      flex-wrap:wrap;\n",
       "      gap: 12px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert {\n",
       "      background-color: #E8F0FE;\n",
       "      border: none;\n",
       "      border-radius: 50%;\n",
       "      cursor: pointer;\n",
       "      display: none;\n",
       "      fill: #1967D2;\n",
       "      height: 32px;\n",
       "      padding: 0 0 0 0;\n",
       "      width: 32px;\n",
       "    }\n",
       "\n",
       "    .colab-df-convert:hover {\n",
       "      background-color: #E2EBFA;\n",
       "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
       "      fill: #174EA6;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert {\n",
       "      background-color: #3B4455;\n",
       "      fill: #D2E3FC;\n",
       "    }\n",
       "\n",
       "    [theme=dark] .colab-df-convert:hover {\n",
       "      background-color: #434B5C;\n",
       "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
       "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
       "      fill: #FFFFFF;\n",
       "    }\n",
       "  </style>\n",
       "\n",
       "      <script>\n",
       "        const buttonEl =\n",
       "          document.querySelector('#df-b96b78f7-abe0-4680-8e76-08bb69674a58 button.colab-df-convert');\n",
       "        buttonEl.style.display =\n",
       "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
       "\n",
       "        async function convertToInteractive(key) {\n",
       "          const element = document.querySelector('#df-b96b78f7-abe0-4680-8e76-08bb69674a58');\n",
       "          const dataTable =\n",
       "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
       "                                                     [key], {});\n",
       "          if (!dataTable) return;\n",
       "\n",
       "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
       "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
       "            + ' to learn more about interactive tables.';\n",
       "          element.innerHTML = '';\n",
       "          dataTable['output_type'] = 'display_data';\n",
       "          await google.colab.output.renderOutput(dataTable, element);\n",
       "          const docLink = document.createElement('div');\n",
       "          docLink.innerHTML = docLinkHtml;\n",
       "          element.appendChild(docLink);\n",
       "        }\n",
       "      </script>\n",
       "    </div>\n",
       "  </div>\n",
       "  "
      ]
     },
     "metadata": {},
     "execution_count": 7
    }
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "# Process dataframe with paths\n",
    "results = nlp.load('pdf2table').predict(df)\n",
    "print_tables(results)"
   ],
   "metadata": {
    "id": "iZfh2aa4PtTe",
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "outputId": "967ce3c5-2255-40ea-fd57-bf500962acf0",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 8,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Table 1:\n",
      "  0_ Volume/\\rModel #                                 Title of Model  \\\n",
      "1             III-360            Consumer Credit Insurance Model Act   \n",
      "2             III-365  Credit Personal Property Insurance Model\\rAct   \n",
      "3             III-370    Consumer Credit Insurance Model\\rRegulation   \n",
      "4             III-375            Creditor-Placed Insurance Model Act   \n",
      "\n",
      "                                         Description  \\\n",
      "1  This model act helps promote the public welfar...   \n",
      "2  This model act 1) Promotes the public welfare ...   \n",
      "3  This model regulation helps protect the intere...   \n",
      "4  This model act creates a legal framework withi...   \n",
      "\n",
      "  Related Charts: State Laws on Insurance Topics 5_  \n",
      "1                                                    \n",
      "2                                                    \n",
      "3      PC-50 - Terrorism and War Risks Exclusion     \n",
      "4                                                    \n",
      "\n",
      "\n",
      "Table 2:\n",
      "  0_  III-385  \\\n",
      "1     III-390   \n",
      "2     III-395   \n",
      "\n",
      "  Model Regulation to Define Standards and\\rCommissioner’s Authority for Companies\\rDeemed to be in Hazardous Financial\\rCondition  \\\n",
      "1                          Model Law on Examinations                                                                                 \n",
      "2  Participation in the NAIC Insurance\\rRegulator...                                                                                 \n",
      "\n",
      "  This model regulation sets forth standards for identifying insurers found to be in such\\rcondition as to render the continuance of their business hazardous to the public or to\\rholders of their policies or certificates of insurance.  \\\n",
      "1  This model law helps provide an effective, eff...                                                                                                                                                                                         \n",
      "2  This model act sets forth the requirements for...                                                                                                                                                                                         \n",
      "\n",
      "                                                  4_ 5_  \n",
      "1  CF-40 - Financial Examinations Standards for I...     \n",
      "2                                                        \n",
      "\n",
      "\n",
      "Table 3:\n",
      "  0_  III-430         Health Maintenance Organization Model\\rAct  \\\n",
      "1     III-432  Model Regulation to Implement Rules\\rRegarding...   \n",
      "\n",
      "  This model act provides for a system of regulation for health maintenance organizations\\rthat is fair and efficient, and promotes the continued solvency of health maintenance\\rorganizations.  \\\n",
      "1  This model regulation implements the NAIC Heal...                                                                                                                                               \n",
      "\n",
      "  HM-10 - Departmental Regulation of HMOs\\rHM-20 - Open Enrollment Periods for HMOs\\rHM-30 - HMO Net Worth and Deposit Requirements  \\\n",
      "1  HM-10 - Departmental Regulation of HMOs\\rHM-20...                                                                                  \n",
      "\n",
      "  5_  \n",
      "1     \n",
      "\n",
      "\n",
      "Table 4:\n",
      "  0_ Volume/\\rModel #                                     Title of Model  \\\n",
      "1             III-440   Insurance Holding Company System\\rRegulatory Act   \n",
      "2             III-450  Insurance Holding Company System Model\\rRegula...   \n",
      "\n",
      "                                         Description  \\\n",
      "1  This model act includes requirements pertainin...   \n",
      "2  This model regulation sets forth rules and pro...   \n",
      "\n",
      "  Related Charts: State Laws on Insurance Topics 5_  \n",
      "1                                                    \n",
      "2                                                    \n",
      "\n",
      "\n",
      "Table 5:\n",
      "  0_  III-460  \\\n",
      "1     III-480   \n",
      "2     III-490   \n",
      "3     III-500   \n",
      "\n",
      "  An Act Concerning Insider Trading of\\rDomestic Stock Insurance Company Equity\\rSecurities  \\\n",
      "1  Regulations Adopted Pursuant to an Act\\rConcer...                                          \n",
      "2  Regulation Regarding Proxies, Consents\\rand Au...                                          \n",
      "3  Stockholders Information Supplement\\rSchedule SIS                                          \n",
      "\n",
      "  This model act includes provisions concerning the unfair use of information, sales of\\requity security, exceptions, definitions and forfeiture. Its corresponding model regulation\\ris MDL-480.  \\\n",
      "1  This model regulation contains definitions and...                                                                                                                                                \n",
      "2  Thismodelregulationprovidesproxyrequirements,f...                                                                                                                                                \n",
      "3  This model contains general instructions, info...                                                                                                                                                \n",
      "\n",
      "  4_ 5_  \n",
      "1        \n",
      "2        \n",
      "3        \n",
      "\n",
      "\n",
      "Table 6:\n",
      "  0_  III-505  \\\n",
      "1     III-510   \n",
      "2     III-520   \n",
      "\n",
      "  Risk Management and Own Risk and\\rSolvency Assessment (ORSA) Model Act  \\\n",
      "1  Criminal Sanctions for Failure to Report\\rImpa...                       \n",
      "2  Life and Health Insurance Guaranty\\rAssociatio...                       \n",
      "\n",
      "  Thismodelactestablishestherequirementsformaintainingariskmanagement\\rframework and completing an Own Risk and Solvency Assessment (ORSA). It addresses\\rexemptions, confidentiality and sanctions.  \\\n",
      "1  This model outlines the criminal sanctions and...                                                                                                                                                   \n",
      "2  This model act protects against failure in the...                                                                                                                                                   \n",
      "\n",
      "                                                  4_ 5_  \n",
      "1                                                        \n",
      "2  IN-10 - Life and Health Guaranty Fund Laws\\rIN...     \n",
      "\n",
      "\n",
      "Table 7:\n",
      "  0_ Volume/\\rModel #                                     Title of Model  \\\n",
      "1             III-540  Property and Casualty Insurance Guaranty\\rAsso...   \n",
      "2             III-555                     Insurer Receivership Model Act   \n",
      "3             III-558               Administrative Supervision Model Act   \n",
      "\n",
      "                                         Description  \\\n",
      "1  This model act provides a mechanism for the pa...   \n",
      "2  This model act helps protect the interests of ...   \n",
      "3  This model act outlines the parameters under w...   \n",
      "\n",
      "      Related Charts: State Laws on Insurance Topics 5_  \n",
      "1  IN-30 - Property and Casualty Guaranty Fund La...     \n",
      "2                                                        \n",
      "3                                                        \n",
      "\n",
      "\n",
      "Table 8:\n",
      "  0_  IV-565  \\\n",
      "1     IV-568   \n",
      "2     IV-570   \n",
      "3     IV-575   \n",
      "4     IV-580   \n",
      "\n",
      "  Group Life Insurance Definition and Group\\rLife Insurance Standard Provisions Model\\rAct  \\\n",
      "1          Military Sales Practices Model Regulation                                         \n",
      "2  Advertisements of Life Insurance and\\rAnnuitie...                                         \n",
      "3  Life and Health Insurance Policy Language\\rSim...                                         \n",
      "4         Life Insurance Disclosure Model Regulation                                         \n",
      "\n",
      "  This model act sets forth group life insurance standard provisions. It defines group life\\rinsurance and contains provisions relating to limits of group life insurance, notice of\\rcompensation, dependent coverage, standard provisions, and a supplementary provision\\rrelating to conversion privileges.  \\\n",
      "1  The purpose of this model regulation is to set...                                                                                                                                                                                                                                                             \n",
      "2  This model regulation sets forth minimum stand...                                                                                                                                                                                                                                                             \n",
      "3  This model act establishes minimum standards f...                                                                                                                                                                                                                                                             \n",
      "4  This model regulation requires insurers to pro...                                                                                                                                                                                                                                                             \n",
      "\n",
      "                                                  4_ 5_  \n",
      "1          PC-50 - Terrorism and War Risks Exclusion     \n",
      "2       LI-30 - Life Insurance Disclosure Provisions     \n",
      "3  LI-20 - Form Filing Requirements Life Insuranc...     \n",
      "4  LI-30 - Life Insurance Disclosure Provisions\\r...     \n",
      "\n",
      "\n",
      "Table 9:\n",
      "     mpg cyl   disp   hp  drat     wt   qsec vs am gear\n",
      "1   21.0   6  160.0  110  3.90  2.620  16.46  0  1    4\n",
      "2   21.0   6  160.0  110  3.90  2.875  17.02  0  1    4\n",
      "3   22.8   4  108.0   93  3.85  2.320  18.61  1  1    4\n",
      "4   21.4   6  258.0  110  3.08  3.215  19.44  1  0    3\n",
      "5   18.7   8  360.0  175  3.15  3.440  17.02  0  0    3\n",
      "6   18.1   6  225.0  105  2.76  3.460  20.22  1  0    3\n",
      "7   14.3   8  360.0  245  3.21  3.570  15.84  0  0    3\n",
      "8   24.4   4  146.7   62  3.69  3.190  20.00  1  0    4\n",
      "9   22.8   4  140.8   95  3.92  3.150  22.90  1  0    4\n",
      "10  19.2   6  167.6  123  3.92  3.440  18.30  1  0    4\n",
      "11  17.8   6  167.6  123  3.92  3.440  18.90  1  0    4\n",
      "12  16.4   8  275.8  180  3.07  4.070  17.40  0  0    3\n",
      "13  17.3   8  275.8  180  3.07  3.730  17.60  0  0    3\n",
      "14  15.2   8  275.8  180  3.07  3.780  18.00  0  0    3\n",
      "15  10.4   8  472.0  205  2.93  5.250  17.98  0  0    3\n",
      "16  10.4   8  460.0  215  3.00  5.424  17.82  0  0    3\n",
      "17  14.7   8  440.0  230  3.23  5.345  17.42  0  0    3\n",
      "18  32.4   4   78.7   66  4.08  2.200  19.47  1  1    4\n",
      "19  30.4   4   75.7   52  4.93  1.615  18.52  1  1    4\n",
      "20  33.9   4   71.1   65  4.22  1.835  19.90  1  1    4\n",
      "21  21.5   4  120.1   97  3.70  2.465  20.01  1  0    3\n",
      "22  15.5   8  318.0  150  2.76  3.520  16.87  0  0    3\n",
      "23  15.2   8  304.0  150  3.15  3.435  17.30  0  0    3\n",
      "24  13.3   8  350.0  245  3.73  3.840  15.41  0  0    3\n",
      "25  19.2   8  400.0  175  3.08  3.845  17.05  0  0    3\n",
      "26  27.3   4   79.0   66  4.08  1.935  18.90  1  1    4\n",
      "27  26.0   4  120.3   91  4.43  2.140  16.70  0  1    5\n",
      "28  30.4   4   95.1  113  3.77  1.513  16.90  1  1    5\n",
      "29  15.8   8  351.0  264  4.22  3.170  14.50  0  1    5\n",
      "30  19.7   6  145.0  175  3.62  2.770  15.50  0  1    5\n",
      "31  15.0   8  301.0  335  3.54  3.570  14.60  0  1    5\n",
      "\n",
      "\n",
      "Table 10:\n",
      "   Sepal.Length Sepal.Width Petal.Length   Petal.Width      Species           \n",
      "1                       5.1          3.5           1.4   0.2 setosa           \n",
      "2                       4.9          3.0           1.4   0.2 setosa           \n",
      "3                       4.7          3.2           1.3   0.2 setosa           \n",
      "4                       4.6          3.1           1.5   0.2 setosa           \n",
      "5                       5.0          3.6           1.4   0.2 setosa           \n",
      "6                       5.4          3.9           1.7   0.4 setosa           \n",
      "7              Sepal.Length  Sepal.Width  Petal.Length  Petal.Width    Species\n",
      "8                   145 6.7          3.3           5.7          2.5  virginica\n",
      "9                   146 6.7          3.0           5.2          2.3  virginica\n",
      "10                  147 6.3          2.5           5.0          1.9  virginica\n",
      "11                  148 6.5          3.0           5.2          2.0  virginica\n",
      "12                  149 6.2          3.4           5.4          2.3  virginica\n",
      "13                  150 5.9          3.0           5.1          1.8  virginica\n",
      "14                                     2                                      \n",
      "\n",
      "\n",
      "Table 11:\n",
      "   supp\n",
      "1    VC\n",
      "2    VC\n",
      "3    VC\n",
      "4    VC\n",
      "5    VC\n",
      "6    VC\n",
      "7    VC\n",
      "8    VC\n",
      "9    VC\n",
      "10   VC\n",
      "11   VC\n",
      "12   VC\n",
      "13   VC\n",
      "14   VC\n",
      "\n",
      "\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Pass a directory which contains PDF files.\n",
    "NLU will recursively search the folder for files which have `.pdf`  suffix in their name and apply the OCR model to it"
   ],
   "metadata": {
    "id": "gJ_0fXolgLMv",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "results = nlp.load('pdf2table' ).predict(\"/content\")\n",
    "print_tables(results)"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "h34lXNiJgISL",
    "outputId": "7e933f96-4bc4-46e8-b3a7-9373ede3c977",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 9,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Table 1:\n",
      "  0_ Volume/\\rModel #                                 Title of Model  \\\n",
      "1             III-360            Consumer Credit Insurance Model Act   \n",
      "2             III-365  Credit Personal Property Insurance Model\\rAct   \n",
      "3             III-370    Consumer Credit Insurance Model\\rRegulation   \n",
      "4             III-375            Creditor-Placed Insurance Model Act   \n",
      "\n",
      "                                         Description  \\\n",
      "1  This model act helps promote the public welfar...   \n",
      "2  This model act 1) Promotes the public welfare ...   \n",
      "3  This model regulation helps protect the intere...   \n",
      "4  This model act creates a legal framework withi...   \n",
      "\n",
      "  Related Charts: State Laws on Insurance Topics 5_  \n",
      "1                                                    \n",
      "2                                                    \n",
      "3      PC-50 - Terrorism and War Risks Exclusion     \n",
      "4                                                    \n",
      "\n",
      "\n",
      "Table 2:\n",
      "  0_  III-385  \\\n",
      "1     III-390   \n",
      "2     III-395   \n",
      "\n",
      "  Model Regulation to Define Standards and\\rCommissioner’s Authority for Companies\\rDeemed to be in Hazardous Financial\\rCondition  \\\n",
      "1                          Model Law on Examinations                                                                                 \n",
      "2  Participation in the NAIC Insurance\\rRegulator...                                                                                 \n",
      "\n",
      "  This model regulation sets forth standards for identifying insurers found to be in such\\rcondition as to render the continuance of their business hazardous to the public or to\\rholders of their policies or certificates of insurance.  \\\n",
      "1  This model law helps provide an effective, eff...                                                                                                                                                                                         \n",
      "2  This model act sets forth the requirements for...                                                                                                                                                                                         \n",
      "\n",
      "                                                  4_ 5_  \n",
      "1  CF-40 - Financial Examinations Standards for I...     \n",
      "2                                                        \n",
      "\n",
      "\n",
      "Table 3:\n",
      "  0_  III-430         Health Maintenance Organization Model\\rAct  \\\n",
      "1     III-432  Model Regulation to Implement Rules\\rRegarding...   \n",
      "\n",
      "  This model act provides for a system of regulation for health maintenance organizations\\rthat is fair and efficient, and promotes the continued solvency of health maintenance\\rorganizations.  \\\n",
      "1  This model regulation implements the NAIC Heal...                                                                                                                                               \n",
      "\n",
      "  HM-10 - Departmental Regulation of HMOs\\rHM-20 - Open Enrollment Periods for HMOs\\rHM-30 - HMO Net Worth and Deposit Requirements  \\\n",
      "1  HM-10 - Departmental Regulation of HMOs\\rHM-20...                                                                                  \n",
      "\n",
      "  5_  \n",
      "1     \n",
      "\n",
      "\n",
      "Table 4:\n",
      "  0_ Volume/\\rModel #                                     Title of Model  \\\n",
      "1             III-440   Insurance Holding Company System\\rRegulatory Act   \n",
      "2             III-450  Insurance Holding Company System Model\\rRegula...   \n",
      "\n",
      "                                         Description  \\\n",
      "1  This model act includes requirements pertainin...   \n",
      "2  This model regulation sets forth rules and pro...   \n",
      "\n",
      "  Related Charts: State Laws on Insurance Topics 5_  \n",
      "1                                                    \n",
      "2                                                    \n",
      "\n",
      "\n",
      "Table 5:\n",
      "  0_  III-460  \\\n",
      "1     III-480   \n",
      "2     III-490   \n",
      "3     III-500   \n",
      "\n",
      "  An Act Concerning Insider Trading of\\rDomestic Stock Insurance Company Equity\\rSecurities  \\\n",
      "1  Regulations Adopted Pursuant to an Act\\rConcer...                                          \n",
      "2  Regulation Regarding Proxies, Consents\\rand Au...                                          \n",
      "3  Stockholders Information Supplement\\rSchedule SIS                                          \n",
      "\n",
      "  This model act includes provisions concerning the unfair use of information, sales of\\requity security, exceptions, definitions and forfeiture. Its corresponding model regulation\\ris MDL-480.  \\\n",
      "1  This model regulation contains definitions and...                                                                                                                                                \n",
      "2  Thismodelregulationprovidesproxyrequirements,f...                                                                                                                                                \n",
      "3  This model contains general instructions, info...                                                                                                                                                \n",
      "\n",
      "  4_ 5_  \n",
      "1        \n",
      "2        \n",
      "3        \n",
      "\n",
      "\n",
      "Table 6:\n",
      "  0_  III-505  \\\n",
      "1     III-510   \n",
      "2     III-520   \n",
      "\n",
      "  Risk Management and Own Risk and\\rSolvency Assessment (ORSA) Model Act  \\\n",
      "1  Criminal Sanctions for Failure to Report\\rImpa...                       \n",
      "2  Life and Health Insurance Guaranty\\rAssociatio...                       \n",
      "\n",
      "  Thismodelactestablishestherequirementsformaintainingariskmanagement\\rframework and completing an Own Risk and Solvency Assessment (ORSA). It addresses\\rexemptions, confidentiality and sanctions.  \\\n",
      "1  This model outlines the criminal sanctions and...                                                                                                                                                   \n",
      "2  This model act protects against failure in the...                                                                                                                                                   \n",
      "\n",
      "                                                  4_ 5_  \n",
      "1                                                        \n",
      "2  IN-10 - Life and Health Guaranty Fund Laws\\rIN...     \n",
      "\n",
      "\n",
      "Table 7:\n",
      "  0_ Volume/\\rModel #                                     Title of Model  \\\n",
      "1             III-540  Property and Casualty Insurance Guaranty\\rAsso...   \n",
      "2             III-555                     Insurer Receivership Model Act   \n",
      "3             III-558               Administrative Supervision Model Act   \n",
      "\n",
      "                                         Description  \\\n",
      "1  This model act provides a mechanism for the pa...   \n",
      "2  This model act helps protect the interests of ...   \n",
      "3  This model act outlines the parameters under w...   \n",
      "\n",
      "      Related Charts: State Laws on Insurance Topics 5_  \n",
      "1  IN-30 - Property and Casualty Guaranty Fund La...     \n",
      "2                                                        \n",
      "3                                                        \n",
      "\n",
      "\n",
      "Table 8:\n",
      "  0_  IV-565  \\\n",
      "1     IV-568   \n",
      "2     IV-570   \n",
      "3     IV-575   \n",
      "4     IV-580   \n",
      "\n",
      "  Group Life Insurance Definition and Group\\rLife Insurance Standard Provisions Model\\rAct  \\\n",
      "1          Military Sales Practices Model Regulation                                         \n",
      "2  Advertisements of Life Insurance and\\rAnnuitie...                                         \n",
      "3  Life and Health Insurance Policy Language\\rSim...                                         \n",
      "4         Life Insurance Disclosure Model Regulation                                         \n",
      "\n",
      "  This model act sets forth group life insurance standard provisions. It defines group life\\rinsurance and contains provisions relating to limits of group life insurance, notice of\\rcompensation, dependent coverage, standard provisions, and a supplementary provision\\rrelating to conversion privileges.  \\\n",
      "1  The purpose of this model regulation is to set...                                                                                                                                                                                                                                                             \n",
      "2  This model regulation sets forth minimum stand...                                                                                                                                                                                                                                                             \n",
      "3  This model act establishes minimum standards f...                                                                                                                                                                                                                                                             \n",
      "4  This model regulation requires insurers to pro...                                                                                                                                                                                                                                                             \n",
      "\n",
      "                                                  4_ 5_  \n",
      "1          PC-50 - Terrorism and War Risks Exclusion     \n",
      "2       LI-30 - Life Insurance Disclosure Provisions     \n",
      "3  LI-20 - Form Filing Requirements Life Insuranc...     \n",
      "4  LI-30 - Life Insurance Disclosure Provisions\\r...     \n",
      "\n",
      "\n",
      "Table 9:\n",
      "     mpg cyl   disp   hp  drat     wt   qsec vs am gear\n",
      "1   21.0   6  160.0  110  3.90  2.620  16.46  0  1    4\n",
      "2   21.0   6  160.0  110  3.90  2.875  17.02  0  1    4\n",
      "3   22.8   4  108.0   93  3.85  2.320  18.61  1  1    4\n",
      "4   21.4   6  258.0  110  3.08  3.215  19.44  1  0    3\n",
      "5   18.7   8  360.0  175  3.15  3.440  17.02  0  0    3\n",
      "6   18.1   6  225.0  105  2.76  3.460  20.22  1  0    3\n",
      "7   14.3   8  360.0  245  3.21  3.570  15.84  0  0    3\n",
      "8   24.4   4  146.7   62  3.69  3.190  20.00  1  0    4\n",
      "9   22.8   4  140.8   95  3.92  3.150  22.90  1  0    4\n",
      "10  19.2   6  167.6  123  3.92  3.440  18.30  1  0    4\n",
      "11  17.8   6  167.6  123  3.92  3.440  18.90  1  0    4\n",
      "12  16.4   8  275.8  180  3.07  4.070  17.40  0  0    3\n",
      "13  17.3   8  275.8  180  3.07  3.730  17.60  0  0    3\n",
      "14  15.2   8  275.8  180  3.07  3.780  18.00  0  0    3\n",
      "15  10.4   8  472.0  205  2.93  5.250  17.98  0  0    3\n",
      "16  10.4   8  460.0  215  3.00  5.424  17.82  0  0    3\n",
      "17  14.7   8  440.0  230  3.23  5.345  17.42  0  0    3\n",
      "18  32.4   4   78.7   66  4.08  2.200  19.47  1  1    4\n",
      "19  30.4   4   75.7   52  4.93  1.615  18.52  1  1    4\n",
      "20  33.9   4   71.1   65  4.22  1.835  19.90  1  1    4\n",
      "21  21.5   4  120.1   97  3.70  2.465  20.01  1  0    3\n",
      "22  15.5   8  318.0  150  2.76  3.520  16.87  0  0    3\n",
      "23  15.2   8  304.0  150  3.15  3.435  17.30  0  0    3\n",
      "24  13.3   8  350.0  245  3.73  3.840  15.41  0  0    3\n",
      "25  19.2   8  400.0  175  3.08  3.845  17.05  0  0    3\n",
      "26  27.3   4   79.0   66  4.08  1.935  18.90  1  1    4\n",
      "27  26.0   4  120.3   91  4.43  2.140  16.70  0  1    5\n",
      "28  30.4   4   95.1  113  3.77  1.513  16.90  1  1    5\n",
      "29  15.8   8  351.0  264  4.22  3.170  14.50  0  1    5\n",
      "30  19.7   6  145.0  175  3.62  2.770  15.50  0  1    5\n",
      "31  15.0   8  301.0  335  3.54  3.570  14.60  0  1    5\n",
      "\n",
      "\n",
      "Table 10:\n",
      "   Sepal.Length Sepal.Width Petal.Length   Petal.Width      Species           \n",
      "1                       5.1          3.5           1.4   0.2 setosa           \n",
      "2                       4.9          3.0           1.4   0.2 setosa           \n",
      "3                       4.7          3.2           1.3   0.2 setosa           \n",
      "4                       4.6          3.1           1.5   0.2 setosa           \n",
      "5                       5.0          3.6           1.4   0.2 setosa           \n",
      "6                       5.4          3.9           1.7   0.4 setosa           \n",
      "7              Sepal.Length  Sepal.Width  Petal.Length  Petal.Width    Species\n",
      "8                   145 6.7          3.3           5.7          2.5  virginica\n",
      "9                   146 6.7          3.0           5.2          2.3  virginica\n",
      "10                  147 6.3          2.5           5.0          1.9  virginica\n",
      "11                  148 6.5          3.0           5.2          2.0  virginica\n",
      "12                  149 6.2          3.4           5.4          2.3  virginica\n",
      "13                  150 5.9          3.0           5.1          1.8  virginica\n",
      "14                                     2                                      \n",
      "\n",
      "\n",
      "Table 11:\n",
      "   supp\n",
      "1    VC\n",
      "2    VC\n",
      "3    VC\n",
      "4    VC\n",
      "5    VC\n",
      "6    VC\n",
      "7    VC\n",
      "8    VC\n",
      "9    VC\n",
      "10   VC\n",
      "11   VC\n",
      "12   VC\n",
      "13   VC\n",
      "14   VC\n",
      "\n",
      "\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Use `ppt2table` spell"
   ],
   "metadata": {
    "id": "FanTreeAhL5A",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### lets download the test `ppt` file first."
   ],
   "metadata": {
    "id": "GijAD4JViF_4",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "!wget https://github.com/JohnSnowLabs/nlu/raw/4.0.0/tests/datasets/ocr/ppt/tables.ppt"
   ],
   "metadata": {
    "id": "jH5VC8y7iACn",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Load and make prediction on *the* test file "
   ],
   "metadata": {
    "id": "qeIcJawKiK1C",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "results = nlp.load('ppt2table').predict(\"/content/tables.ppt\")\n",
    "print_tables(results)"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "JIulvrhnhLT8",
    "outputId": "00b3ea4f-4874-42e5-eb77-c6ec230b6d1f",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 11,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Table 1:\n",
      "                          mpg cyl   disp   hp  drat     wt   qsec vs am gear  \\\n",
      "1             Mazda RX4  21.0   6  160.0  110  3.90  2.620  16.46  0  1    4   \n",
      "2         Mazda RX4 Wag  21.0   6  160.0  110  3.90  2.875  17.02  0  1    4   \n",
      "3            Datsun 710  22.8   4  108.0   93  3.85  2.320  18.61  1  1    4   \n",
      "4        Hornet 4 Drive  21.4   6  258.0  110  3.08  3.215  19.44  1  0    3   \n",
      "5     Hornet Sportabout  18.7   8  360.0  175  3.15  3.440  17.02  0  0    3   \n",
      "6               Valiant  18.1   6  225.0  105  2.76  3.460  20.22  1  0    3   \n",
      "7            Duster 360  14.3   8  360.0  245  3.21  3.570  15.84  0  0    3   \n",
      "8             Merc 240D  24.4   4  146.7   62  3.69  3.190  20.00  1  0    4   \n",
      "9              Merc 230  22.8   4  140.8   95  3.92  3.150  22.90  1  0    4   \n",
      "10             Merc 280  19.2   6  167.6  123  3.92  3.440  18.30  1  0    4   \n",
      "11            Merc 280C  17.8   6  167.6  123  3.92  3.440  18.90  1  0    4   \n",
      "12           Merc 450SE  16.4   8  275.8  180  3.07  4.070  17.40  0  0    3   \n",
      "13           Merc 450SL  17.3   8  275.8  180  3.07  3.730  17.60  0  0    3   \n",
      "14          Merc 450SLC  15.2   8  275.8  180  3.07  3.780  18.00  0  0    3   \n",
      "15   Cadillac Fleetwood  10.4   8  472.0  205  2.93  5.250  17.98  0  0    3   \n",
      "16  Lincoln Continental  10.4   8  460.0  215  3.00  5.424  17.82  0  0    3   \n",
      "17    Chrysler Imperial  14.7   8  440.0  230  3.23  5.345  17.42  0  0    3   \n",
      "18             Fiat 128  32.4   4   78.7   66  4.08  2.200  19.47  1  1    4   \n",
      "19          Honda Civic  30.4   4   75.7   52  4.93  1.615  18.52  1  1    4   \n",
      "20       Toyota Corolla  33.9   4   71.1   65  4.22  1.835  19.90  1  1    4   \n",
      "21        Toyota Corona  21.5   4  120.1   97  3.70  2.465  20.01  1  0    3   \n",
      "22     Dodge Challenger  15.5   8  318.0  150  2.76  3.520  16.87  0  0    3   \n",
      "23          AMC Javelin  15.2   8  304.0  150  3.15  3.435  17.30  0  0    3   \n",
      "24           Camaro Z28  13.3   8  350.0  245  3.73  3.840  15.41  0  0    3   \n",
      "25     Pontiac Firebird  19.2   8  400.0  175  3.08  3.845  17.05  0  0    3   \n",
      "26            Fiat X1-9  27.3   4   79.0   66  4.08  1.935  18.90  1  1    4   \n",
      "27        Porsche 914-2  26.0   4  120.3   91  4.43  2.140  16.70  0  1    5   \n",
      "28         Lotus Europa  30.4   4   95.1  113  3.77  1.513  16.90  1  1    5   \n",
      "29       Ford Pantera L  15.8   8  351.0  264  4.22  3.170  14.50  0  1    5   \n",
      "30         Ferrari Dino  19.7   6  145.0  175  3.62  2.770  15.50  0  1    5   \n",
      "31        Maserati Bora  15.0   8  301.0  335  3.54  3.570  14.60  0  1    5   \n",
      "32           Volvo 142E  21.4   4  121.0  109  4.11  2.780  18.60  1  1    4   \n",
      "\n",
      "   carb  \n",
      "1     4  \n",
      "2     4  \n",
      "3     1  \n",
      "4     1  \n",
      "5     2  \n",
      "6     1  \n",
      "7     4  \n",
      "8     2  \n",
      "9     2  \n",
      "10    4  \n",
      "11    4  \n",
      "12    3  \n",
      "13    3  \n",
      "14    3  \n",
      "15    4  \n",
      "16    4  \n",
      "17    4  \n",
      "18    1  \n",
      "19    2  \n",
      "20    1  \n",
      "21    1  \n",
      "22    2  \n",
      "23    2  \n",
      "24    4  \n",
      "25    2  \n",
      "26    1  \n",
      "27    2  \n",
      "28    2  \n",
      "29    4  \n",
      "30    6  \n",
      "31    8  \n",
      "32    2  \n",
      "\n",
      "\n",
      "Table 2:\n",
      "  Sepal.Length Sepal.Width Petal.Length Petal.Width Species\n",
      "1          5.1         3.5          1.4         0.2  setosa\n",
      "2          4.9         3.0          1.4         0.2  setosa\n",
      "3          4.7         3.2          1.3         0.2  setosa\n",
      "4          4.6         3.1          1.5         0.2  setosa\n",
      "5          5.0         3.6          1.4         0.2  setosa\n",
      "6          5.4         3.9          1.7         0.4  setosa\n",
      "\n",
      "\n",
      "Table 3:\n",
      "       Sepal.Length Sepal.Width Petal.Length Petal.Width    Species\n",
      "1  145          6.7         3.3          5.7         2.5  virginica\n",
      "2  146          6.7         3.0          5.2         2.3  virginica\n",
      "3  147          6.3         2.5          5.0         1.9  virginica\n",
      "4  148          6.5         3.0          5.2         2.0  virginica\n",
      "5  149          6.2         3.4          5.4         2.3  virginica\n",
      "6  150          5.9         3.0          5.1         1.8  virginica\n",
      "\n",
      "\n",
      "Table 4:\n",
      "     len supp dose\n",
      "1    4.2   VC  0.5\n",
      "2   11.5   VC  0.5\n",
      "3    7.3   VC  0.5\n",
      "4    5.8   VC  0.5\n",
      "5    6.4   VC  0.5\n",
      "6   10.0   VC  0.5\n",
      "7   11.2   VC  0.5\n",
      "8   11.2   VC  0.5\n",
      "9    5.2   VC  0.5\n",
      "10   7.0   VC  0.5\n",
      "11  16.5   VC  1.0\n",
      "12  16.5   VC  1.0\n",
      "13  15.2   VC  1.0\n",
      "14  17.3   VC  1.0\n",
      "15  22.5   VC  1.0\n",
      "\n",
      "\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Use `doc2table` spell"
   ],
   "metadata": {
    "id": "e4ue48keibqF",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### lets download the test `DOC/DOCX` file first."
   ],
   "metadata": {
    "id": "cjHHVNLZijEa",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "!wget https://github.com/JohnSnowLabs/nlu/raw/4.0.0/tests/datasets/ocr/docx_with_table/doc2.docx\n"
   ],
   "metadata": {
    "id": "GIbVgmi0ieLQ",
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Load and make prediction on *the* test file "
   ],
   "metadata": {
    "id": "TZYyAoyxiks_",
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "results = nlp.load('doc2table').predict(\"/content/doc2.docx\")\n",
    "print_tables(results)"
   ],
   "metadata": {
    "id": "VsD3iPzsinDd",
    "pycharm": {
     "name": "#%%\n"
    },
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "outputId": "92c8ddda-2365-486a-b1af-178517e79042"
   },
   "execution_count": 13,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Table 1:\n",
      "   Screen Reader Responses Share\n",
      "1           JAWS       853   49%\n",
      "2           NVDA       238   14%\n",
      "3    Window-Eyes       214   12%\n",
      "4  System Access       181   10%\n",
      "5      VoiceOver       159    9%\n",
      "\n",
      "\n",
      "Table 2:\n",
      "                   May 2012  September 2010\n",
      "1  Screen Reader  Responses           Share\n",
      "2           JAWS        853             49%\n",
      "3           NVDA        238             14%\n",
      "4    Window-Eyes        214             12%\n",
      "5  System Access        181             10%\n",
      "6      VoiceOver        159              9%\n",
      "\n",
      "\n"
     ]
    }
   ]
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "machine_shape": "hm",
   "name": "table_extractionv2.ipynb",
   "provenance": [],
   "toc_visible": true
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
